package com.jsmtr.rms.controller;

import java.text.SimpleDateFormat;
import java.util.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.jsmtr.rms.entity.*;
import com.jsmtr.rms.service.IDoResumeService;
import com.jsmtr.rms.service.IDoSZService;
import com.jsmtr.rms.service.IProjectService;
import com.jsmtr.rms.service.IUtilService;
import com.jsmtr.rms.utils.EnumTools;
import com.jsmtr.rms.utils.PhoneTools;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/Do/SZPhysical")
public class DoSZPhysicalController {

    @Resource
    private IUtilService utilService;
    @Resource
    private IDoSZService szService;
    @Resource
    private IDoResumeService doResumeService;
    @Resource
    private IProjectService projectService;

    //[start] 体检管理
    @RequestMapping("/")
    public String Index(HttpServletRequest request, HttpServletResponse response, Model model) {
        try {
            model.addAttribute("path", request.getContextPath());
            String pid = request.getParameter("pid").trim();
            String fid = request.getParameter("fid").trim();
            String deptcode = request.getParameter("deptcode").trim();

            model.addAttribute("pid", pid);
            model.addAttribute("fid", fid);
            model.addAttribute("deptcode", deptcode);

            //名族
            model.addAttribute("minzu", utilService.optionList("B", "0"));
            //婚否
            model.addAttribute("hunfou", utilService.optionList("D", "0"));
            //政治面貌
            model.addAttribute("zzmm", utilService.optionList("E", "0"));
            //最高学历
            model.addAttribute("education", utilService.optionList("F", "0"));
            //专业技术职务类型
            model.addAttribute("posttype", utilService.optionList("I", "0"));
            //职业资格证
            model.addAttribute("jndj", utilService.optionList("O", "0"));
            //招聘岗位
           /* List<ProjectInfoJobs> jobs = projectService.getjobsbypid(pid);
            StringBuilder dstr = new StringBuilder();
            for (ProjectInfoJobs job : jobs) {
                dstr.append("<option value='" + job.getJobname() + "'>" + job.getJobname() + "</option>");
            }
            model.addAttribute("jobs", dstr);
*/
            //招聘岗位
            List<ProjectInfoJobs> projectJobs=utilService.getProjectJobs(pid);
            model.addAttribute("jobs",projectJobs);

            List<BaseConfig> configs = utilService.getConfigs("dzmb");
            StringBuilder str1 = new StringBuilder();
            for (BaseConfig config : configs) {
                str1.append("<option value='" + config.getCont() + "'>" + config.getCont() + "</option>");
            }
            model.addAttribute("address", str1);

            List<BaseConfig> _configs = utilService.getConfigs("dxmb");
            StringBuilder str3 = new StringBuilder();
            for (BaseConfig _config : _configs) {
                str3.append("<option value='" + _config.getCode() + "'>" + _config.getName() + "</option>");
            }
            model.addAttribute("dxmb", str3);

            //面试注意事项
            String tjzysx=utilService.getConfig("tjzysx");
            model.addAttribute("tjzysx",tjzysx);

        } catch (Exception e) {
            e.printStackTrace();
        }
        return "Do/SZ/Physical/index";
    }

    @SuppressWarnings("unchecked")
  /*  @RequestMapping("/getusers")
    public void getusers(HttpServletRequest request, HttpServletResponse response, DUserResume user) {
        try {
            int perpage = Integer.parseInt(request.getParameter("perpage"));
            int page = Integer.parseInt(request.getParameter("page"));
            String flowid = request.getParameter("flowid").trim();

            Map<String, Object> _map = new HashMap<String, Object>();
            _map.put("agefrom", request.getParameter("agefrom").trim());
            _map.put("ageto", request.getParameter("ageto").trim());
            _map.put("workyearfrom", request.getParameter("workyearfrom").trim());
            _map.put("workyearto", request.getParameter("workyearto").trim());
            _map.put("heightfrom", request.getParameter("heightfrom").trim());
            _map.put("heightto", request.getParameter("heightto").trim());

            Map<String, Object> map = szService.getResumesMap(page, perpage, user, _map);
            StringBuilder result = new StringBuilder();
            double pageCount = (Double) map.get("pageCount");
            double allcount = (Double) map.get("count");
            if (pageCount != 0) {
                *//*Object object = map.get("list");
                for (DUserResume _user : (List<DUserResume>) object) {
                    result.append("<tr><td><input type='checkbox' id='cb_" + _user.getId() + "' value='" + _user.getId() + "' /></td>");
                    result.append("<td>" + _user.getCode() + "</td>");
                    result.append("<td>" + _user.getJname() + "</td>");
                    result.append("<td class='link'><a target='_blank' href='"
                            + request.getContextPath() + "/Do/SZResume/View?id="
                            + _user.getId() + "'>" + _user.getName()
                            + "</a></td>");
                    result.append("<td>" + _user.getCardno() + "</td>");
                    result.append("<td>" + _user.getEducationname() + "</td>");
                    result.append("<td>" + _user.getWorkexperience() + "年</td>");
                    result.append("<td>" + _user.getTel() + "</td>");
                    result.append("<td title='联系人：" + _user.getTjlxr() + " " + _user.getTjlxdh() + "\n体检地址：" + _user.getTjaddress() + "'>" + (_user.getTjtime() == null ? "" : _user.getTjtime()) + "</td>");
                    result.append("<td>" + _user.getTjmsg() + "</td>");
                    result.append("<td>" + (_user.getTjstate() == null ? "" : _user.getTjstate()) + "</td>");
                    result.append("<td>" + (_user.getTjremark() == null ? "" : _user.getTjremark()) + "</td>");
                    if (_user.getOp4() == null || _user.getOp4().equals("未公布")) {
                        result.append("<td class='true'><span>未公布</span></td>");
                    } else {
                        result.append("<td class='false'><span>已公布</span></td>");
                    }

                    if (_user.getFqstate().equals("已放弃") && _user.getFqfid().equals(flowid)) {
                        result.append("<td class='yfq'><span>已放弃</span></td></tr>");
                    } else {
                        if (_user.getNrid() != null) {
                            result.append("<td class='ytj'><span title='" + _user.getNjname() + "'>已推荐</span></td></tr>");
                        } else {
                            if (_user.getTjstate() == null) {
                                result.append("<td class='true'><span>未完成</td></tr>");
                            } else {
                                if (_user.getTjstate().equals("不合格")) {
                                    result.append("<td class='false'><span>已完成</td></tr>");
                                } else {
                                    if (_user.getFid().equals(flowid)) {
                                        result.append("<td class='true'><span>未完成</td></tr>");
                                    } else {
                                        result.append("<td class='false'><span>已完成</td></tr>");
                                    }
                                }
                            }
                        }
                    }
                }*//*
                List<HashMap> object = (List<HashMap>)map.get("list");
                for (HashMap<String,Object> _user :  object) {
                    result.append("<tr><td><input type='checkbox' id='cb_" + _user.get("ID") + "' value='" + _user.get("ID") + "' /></td>");
                    result.append("<td class='link'><a target='_blank' href='"
                            + request.getContextPath() + "/UserResume/ViewDResume?id="
                            + _user.get("ID") + "'>" + _user.get("NAME")
                            + "</a></td>");
                    result.append("<td>" + _user.get("CARDNO") + "</td>");
                   // result.append("<td>" + _user.get("EDUCATIONNAME") + "</td>");
                    result.append("<td>" + (_user.get("EDUCATIONNAME") == null ? "" : _user.get("EDUCATIONNAME")) +  "</td>");
                   // result.append("<td>" + _user.get("WORKEXPERIENCE") + "年</td>");
                    result.append("<td>" + (_user.get("WORKEXPERIENCE") == null ? "" : (_user.get("WORKEXPERIENCE")+"年")) +  "</td>");
                    result.append("<td>" + _user.get("JNAME") + "</td>");
                    result.append("<td>" + _user.get("TEL") + "</td>");
                    result.append("<td>" + (_user.get("TJTIME") == null ? "" : _user.get("TJTIME")) +  "</td>");
                    result.append("<td>" +( _user.get("TJADDRESS")==null ? "" : _user.get("TJADDRESS")) + "</td>");
                    result.append("<td>" + (_user.get("TJLXR")==null?"": _user.get("TJLXR")+ "" + _user.get("TJLXDH")==null?"": _user.get("TJLXDH"))+"</td>");
                    result.append("<td>" + _user.get("TJMSG") + "</td>");
                    result.append("<td>" + (_user.get("TJSTATE") == null ? "" : _user.get("TJSTATE")) + "</td>");
                    result.append("<td>" + (_user.get("TJREMARK") == null ? "" : _user.get("TJREMARK")) + "</td>");

                    if (_user.get("OP4") == null || _user.get("OP4").equals("未公布")) {
                        result.append("<td>"+ (_user.get("MCONTENT") == null ? "" : _user.get("MCONTENT")) + "</td>");
                        result.append("<td class='true'><span>未公布</span></td>");
                    } else {
                        result.append("<td>"+"最近登录："+ (_user.get("LOGINTIME")==null?"":_user.get("LOGINTIME").toString())+"<br/>个人情况：" + (_user.get("MCONTENT") == null ? "" : _user.get("MCONTENT")) + "</td>");
                        result.append("<td class='false'><span>已公布</span></td>");
                    }
                    if (_user.get("FQSTATE").equals("已放弃") && _user.get("FQFID").equals(flowid)) {
                        result.append("<td class='yfq'><span>已放弃</span></td></tr>");
                    } else {
                        if (_user.get("NRID") != null) {
                            result.append("<td class='ytj'><span title='" + _user.get("NJNAME") + "'>已推荐</span></td></tr>");
                        } else {
                            if (_user.get("TJSTATE") == null) {
                                result.append("<td class='true'><span>未完成</td></tr>");
                            } else {
                                if (_user.get("TJSTATE").equals("不合格")||_user.get("TJSTATE").equals("未通过")||_user.get("TJSTATE").equals("不通过")) {
                                    result.append("<td class='false'><span>已完成</td></tr>");
                                } else {
                                    if (_user.get("FID").equals(flowid)) {
                                        result.append("<td class='true'><span>未完成</td></tr>");
                                    } else {
                                        result.append("<td class='false'><span>已完成</td></tr>");
                                    }
                                }
                            }
                        }
                    }
                }

            } else {
                result.append("<tr><td colspan='20'>未找到符合条件的数据</td></tr>");
            }
            result.append("<input type='hidden' id='pageCount' value='" + pageCount + "' />");
            result.append("<input type='hidden' id='allCount' value='" + allcount + "' />");
            utilService.printTextResult(result.toString(), response);
        } catch (Exception e) {
            e.printStackTrace();
            utilService.printTextResult("<tr><td colspan='20'>读取数据失败</td></tr><input type='hidden' id='pageCount' value='0' /><input type='hidden' id='allCount' value='0' />", response);
        }

    }*/

    //[end]
    @ResponseBody
    @RequestMapping(value = "/getSzPhysicalListLayuiJson", method = RequestMethod.GET)
    public LayuiDataTableResultBean getSzPhysicalListLayuiJson(HttpServletRequest request, HttpServletResponse response, DUserResume user) {
        try {
            int page = Integer.parseInt(request.getParameter("page"));
            int limit = Integer.parseInt(request.getParameter("limit"));
            String flowid = request.getParameter("flowid").trim();

            Map<String, Object> _map = new HashMap<String, Object>();
            _map.put("agefrom", request.getParameter("agefrom").trim());
            _map.put("ageto", request.getParameter("ageto").trim());
            _map.put("workyearfrom", request.getParameter("workyearfrom").trim());
            _map.put("workyearto", request.getParameter("workyearto").trim());
            _map.put("heightfrom", request.getParameter("heightfrom").trim());
            _map.put("heightto", request.getParameter("heightto").trim());

            Map<String, Object> map = szService.getResumesMap(page, limit, user, _map);

            double pageCount = (Double) map.get("pageCount");
            double allcount = (Double) map.get("count");
            JSONArray jsonArray = new JSONArray();
            int num = 1;

            if (pageCount != 0) {
                List<HashMap> object = (List<HashMap>)map.get("list");
                for (HashMap<String,Object> _user :  object) {
                    JSONObject jsonObject = new JSONObject();
                    jsonObject.put("id_cb", "cb_" + _user.get("ID"));
                    jsonObject.put("id", limit * (page - 1) + num);
                    jsonObject.put("NAME", _user.get("NAME"));
                    jsonObject.put("cardcount", Integer.parseInt(_user.get("CARDCOUNT").toString()));
                    jsonObject.put("ContextPath", request.getContextPath() + "/UserResume/ViewDResume?id=" + _user.get("ID"));
                    jsonObject.put("CARDNO", _user.get("CARDNO"));
                    jsonObject.put("EDUCATIONNAME", (_user.get("EDUCATIONNAME") == null ? "" : _user.get("EDUCATIONNAME")));
                    jsonObject.put("WORKEXPERIENCE", (_user.get("WORKEXPERIENCE") == null ? "" : (_user.get("WORKEXPERIENCE")+"年")));
                    jsonObject.put("JNAME", _user.get("JNAME"));
                    jsonObject.put("TEL", _user.get("TEL"));
                    jsonObject.put("TJTIME", (_user.get("TJTIME") == null ? "" : _user.get("TJTIME")));
                    jsonObject.put("TJADDRESS", (_user.get("TJADDRESS") == null ? "" : _user.get("TJADDRESS")));
                    jsonObject.put("TJLXRs", (_user.get("TJLXR")==null?"": _user.get("TJLXR")+ "" + _user.get("TJLXDH")==null?"": _user.get("TJLXDH")));
                    jsonObject.put("TJMSG", _user.get("TJMSG"));
                    jsonObject.put("TJSTATE", _user.get("TJSTATE"));
                    jsonObject.put("TJREMARK", (_user.get("TJREMARK") == null ? "" : _user.get("TJREMARK")));
                    jsonObject.put("MID", _user.get("MID"));
                    jsonObject.put("MCONTENT", (_user.get("MCONTENT") == null ? "" : _user.get("MCONTENT")));

                    if (_user.get("OP4") == null || _user.get("OP4").equals("未公布")) {
                        jsonObject.put("STATEa", (_user.get("MCONTENT") == null ? "" : _user.get("MCONTENT")));
                        jsonObject.put("STATEb", "未公布");
                    } else {
                        jsonObject.put("LOGINTIME", (_user.get("LOGINTIME")==null?"":_user.get("LOGINTIME").toString()));
                        jsonObject.put("STATEa", (_user.get("MCONTENT") == null ? "" : _user.get("MCONTENT")));
                        jsonObject.put("STATEb","已公布");
                    }
                    jsonObject.put("FQSTATE", _user.get("FQSTATE"));
                    jsonObject.put("TJSTATE", _user.get("TJSTATE"));
                    jsonObject.put("FID", _user.get("FID"));
                    jsonObject.put("NRID", _user.get("NRID"));
                    if (_user.get("FQSTATE").equals("已放弃") && _user.get("FQFID").equals(flowid)) {
                       jsonObject.put("STATEc", "已放弃");
                    } else {
                        if (_user.get("NRID") != null) {
                            jsonObject.put("STATEc", "已推荐");
                        } else {
                            if (_user.get("TJSTATE") == null) {
                                jsonObject.put("STATEc", "未完成");
                            } else {
                                if (_user.get("TJSTATE").equals("不合格")||_user.get("TJSTATE").equals("未通过")||_user.get("TJSTATE").equals("不通过")) {
                                    jsonObject.put("STATEc", "已完成");
                                } else {
                                    if (_user.get("FID").equals(flowid)) {
                                        jsonObject.put("STATEc", "未完成");
                                    } else {
                                        jsonObject.put("STATEc", "已完成");
                                    }
                                }
                            }
                        }
                    }

                    jsonObject.put("arrange", _user.get("TJARRANGE"));

                    jsonArray.add(jsonObject);
                    num++;
                }
            }


            LayuiDataTableResultBean result = new LayuiDataTableResultBean();
            result.setCode(0);
            result.setMsg("success");
            result.setCount((int) allcount);
            result.setData(jsonArray);

            return result;
        } catch (Exception e) {
            e.printStackTrace();

            LayuiDataTableResultBean result = new LayuiDataTableResultBean();
            result.setCount(-1);
            result.setMsg("err");
            return result;
        }
    }



    //[start] 体检安排

    @RequestMapping(value = "/PlanAction", method = RequestMethod.POST)
    public void PlanAction(HttpServletRequest request, HttpServletResponse response, DUserResume _user) {
        try {
            String[] uids = request.getParameterValues("uid");
            if (uids == null) {
                utilService.printJsonResult(false, "请选择参加体检的应聘者!", "no", response);
            } else {
                String deptcode = request.getParameter("deptcode").trim();//责任部门编码
                String fid = request.getParameter("fid").trim();//招聘流程ID
                String tjzysx=request.getParameter("tjzysx");
                String pid=request.getParameter("pid");
                BaseUser cuser = utilService.getSessionUser(request);
                if (cuser.getUdept().equals(deptcode)) {
                    //流程是否结束
                    if (utilService.FlowIsDoing(fid)) {
                        List editlist = new ArrayList();
                        List<DUserResume> users = szService.getResumes(uids);
                        List<DoZysx> zysxList=new ArrayList<>();
                        for (DUserResume user : users) {
                            if (user.getFqstate().equals("未放弃")
                                    && user.getFid().equals(fid)
                                    && user.getTjmsg().equals("未发通知")
                                    && user.getNrid() == null) {
                                user.setTjtime(_user.getTjtime());
                                user.setTjaddress(_user.getTjaddress());
                                user.setTjlxr(_user.getTjlxr());
                                user.setTjlxdh(_user.getTjlxdh());
                                editlist.add(user);
                            }

                            if(tjzysx!=null&&tjzysx.trim().length()>0){
                                DoZysx userZysx= utilService.getUserZysx(pid,fid,user.getId());
                                DoZysx zysx=null;
                                if (userZysx==null){
                                    zysx=new DoZysx();
                                    zysx.setId(UUID.randomUUID().toString());
                                    zysx.setFid(fid);
                                    zysx.setPid(pid);
                                    zysx.setRemark(tjzysx);
                                    zysx.setUserid(user.getId());
                                    zysx.setType("TJ");
                                    zysx.setAddtime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
                                    zysx.setAdduser(cuser.getUcode());
                                    zysxList.add(zysx);
                                }else{
                                    zysx=userZysx;
                                    zysx.setRemark(tjzysx);
                                    zysx.setType("TJ");
                                    zysx.setAddtime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
                                    zysx.setAdduser(cuser.getUcode());
                                    editlist.add(zysx);
                                }

                            }
                        }

                        if (editlist.size() > 0) {
                            utilService.editList(editlist);
                            if(zysxList.size()>0) {
                                utilService.addList(zysxList);
                            }
                            utilService.printJsonResult(true, "操作成功！", "no", response);
                        } else {
                            utilService.printJsonResult(false, "当前信息不能执行此操作！", "no", response);
                        }
                    } else {
                        utilService.printJsonResult(false, "当前流程不支持此操作！", "no", response);
                    }
                } else {
                    utilService.printJsonResult(false, "您无权执行此操作！", "no", response);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            utilService.printJsonResult(false, "操作失败!", "no", response);
        }
    }

    //[end]

    //[start] 发布体检通知

    @RequestMapping(value = "/MsgAction", method = RequestMethod.POST)
    public void MsgAction(HttpServletRequest request, HttpServletResponse response) {
        try {
            String[] uids = request.getParameterValues("uid");
            if (uids == null) {
                utilService.printJsonResult(false, "请选择参加体检的应聘者!", "no", response);
            } else {
                String fid = request.getParameter("fid").trim();//招聘流程ID
                String deptcode = request.getParameter("deptcode").trim();//责任部门编码

                BaseUser cuser = utilService.getSessionUser(request);
                if (cuser.getUdept().equals(deptcode)) {
                    //流程是否结束
                    if (utilService.FlowIsDoing(fid)) {
                        List<DUserResume> editlist = new ArrayList<DUserResume>();
                        String dxnr = request.getParameter("dxnr").trim();

                        List<Map<String, String>> msgs = new ArrayList<Map<String, String>>();

                        List<DUserResume> users = szService.getResumes(uids);

                        for (DUserResume user : users) {
                            if (user.getTjmsg().equals("未发通知")
                                    && user.getFid().equals(fid)
                                    && user.getFqstate().equals("未放弃")
                                    && user.getTjtime() != null
                                    && user.getNrid() == null) {
                                user.setTjmsg("已发通知");
                                editlist.add(user);

                                //-------------短信----------------
                                Map<String, String> _map = new HashMap<String, String>();
                                _map.put("tel", user.getTel());
                                _map.put("cont", dxnr.replace("{姓名}", user.getName()).replace("{时间}", user.getTjtime()).replace("{地点}", user.getTjaddress()));
                                msgs.add(_map);
                            }
                        }
                        if (editlist.size() > 0) {
                            utilService.editList(editlist);
                            BaseMessageConfig messageConfig=utilService.getMessageConfig();
                            //发送短信
                            if (PhoneTools.sendMsg(msgs,messageConfig.getUsername(),messageConfig.getPassword(),messageConfig.getHost())) {
                                utilService.printJsonResult(true, "操作成功！", "no", response);
                            } else {
                                utilService.printJsonResult(false, "短信发送失败！", "no", response);
                            }
                        } else {
                            utilService.printJsonResult(false, "当前信息不能执行此操作！", "no", response);
                        }
                    } else {
                        utilService.printJsonResult(false, "当前流程不支持此操作！", "no", response);
                    }
                } else {
                    utilService.printJsonResult(false, "您无权执行此操作！", "no", response);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            utilService.printJsonResult(false, "操作失败！", "no", response);
        }
    }

    //[end]

    //[start] 体检结果
    @RequestMapping(value = "/RAction", method = RequestMethod.POST)
    public void RAction(HttpServletRequest request, HttpServletResponse response) {
        try {
            String[] uids = request.getParameterValues("uid");
            if (uids == null) {
                utilService.printJsonResult(false, "请选择人员！", "no", response);
            } else {
                String fid = request.getParameter("fid").trim();//招聘流程ID
                String deptcode = request.getParameter("deptcode").trim();//责任部门编码
                String tjstate = request.getParameter("tjstate").trim();//体检结果
                String tjremark = request.getParameter("tjremark").trim();//体检备注

                BaseUser cuser = utilService.getSessionUser(request);
                if (cuser.getUdept().equals(deptcode)) {
                    if (utilService.FlowIsDoing(fid)) {
                        List<DUserResume> editList = new ArrayList<DUserResume>();
                        List<DUserResume> users = szService.getResumes(uids);
                        for (DUserResume user : users) {
                            if (user.getFqstate().equals("未放弃")
                                    && user.getFid().equals(fid)
                                    /*&& !tjstate.equals(user.getTjstate())*/
                                    && user.getNrid() == null) {
                                user.setTjdate(new Date());
                                user.setTjremark(tjremark);
                                user.setTjstate(tjstate);
                                user.setTjuid(cuser.getId());
                                user.setTjuname(cuser.getUname());
                                editList.add(user);
                            }
                        }

                        if (editList.size() > 0) {
                            utilService.editList(editList);
                            utilService.printJsonResult(true, "操作成功！", "no", response);
                        } else {
                            utilService.printJsonResult(false, "当前选中信息不支持此操作！", "no", response);
                        }
                    } else {
                        utilService.printJsonResult(false, "当前流程不支持此操作！", "no", response);
                    }
                } else {
                    utilService.printJsonResult(false, "您无权执行此操作！", "no", response);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            utilService.printJsonResult(false, "操作失败", "no", response);
        }
    }
    //[end]

    //[start] 流程扭转到下一步

    @SuppressWarnings({"rawtypes", "unchecked"})
    @RequestMapping(value = "/NextAction", method = RequestMethod.POST)
    public void NextAction(HttpServletRequest request, HttpServletResponse response) {
        try {
            String[] ids = request.getParameterValues("id");//人员信息ID
            if (ids != null) {
                String pid = request.getParameter("pid").trim();//招聘方案ID
                String fid = request.getParameter("fid").trim();//招聘流程ID
                String deptcode = request.getParameter("deptcode").trim();//责任部门编码
                BaseUser usr = utilService.getSessionUser(request);
                if (usr.getUdept().equals(deptcode)) {
                    //流程是否结束
                    if (utilService.FlowIsDoing(fid)) {
                        List editlist = new ArrayList();
                        List<DUserResume> users = szService.getResumes(ids);
                        ProjectInfoFlow nFlow = szService.getNextFlow(pid, deptcode, fid);

                        for (DUserResume user : users) {
                            if (user.getFid().equals(fid)
                                    && user.getFqstate().equals("未放弃")
                                    && user.getNrid() == null) {
                                if( user.getTjstate().equalsIgnoreCase("合格")||user.getTjstate().equalsIgnoreCase("已合格")||user.getTjstate().equalsIgnoreCase("通过")||user.getTjstate().equalsIgnoreCase("已通过")){
                                    user.setFid(nFlow.getId());
                                    user.setPath(user.getPath() + nFlow.getId() + "/");
                                    editlist.add(user);
                                }
                            }
                        }

                        if (editlist.size() > 0) {
                            nFlow.setState(EnumTools.PlanFlowState.进行中.ordinal());
                            editlist.add(nFlow);

                            utilService.editList(editlist);
                            utilService.printJsonResult(true, "操作成功！", "no", response);
                        } else {
                            utilService.printJsonResult(false, "当前选中的信息不能执行此操作！", "no", response);
                        }
                    } else {
                        utilService.printJsonResult(false, "当前流程不支持此操作！", "no", response);
                    }
                } else {
                    utilService.printJsonResult(false, "您无权执行此操作！", "no", response);
                }
            } else {
                utilService.printJsonResult(false, "请选择人员信息！", "no", response);
            }
        } catch (Exception e) {
            e.printStackTrace();
            utilService.printJsonResult(false, "操作失败！", "no", response);
        }
    }

    //[end]
}
